package com.sd.struts2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import org.apache.struts2.components.Date;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class DeclarativeAction extends ActionSupport{
	
	private String ename,pass,repass,email,address;
	
	java.sql.Date doj;
	Connection con;

	
	public java.sql.Date getDoj() {
		return doj;
	}

	public void setDoj(java.sql.Date doj) {
		this.doj = doj;
	}

	public String getEname() {
		return ename;
	}

	public void setEname(String ename) {
		this.ename = ename;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getRepass() {
		return repass;
	}

	public void setRepass(String repass) {
		this.repass = repass;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	public String execute(){
		try{
			con=getCon();
			System.out.println("in try");
			PreparedStatement ps=con.prepareStatement("insert into declarativetable values(?,?,?,?,?,?)");
			System.out.println("in pre-statm");
			ps.setString(1,ename);
			ps.setString(2,pass);
			ps.setString(3,repass);
			ps.setDate(4, doj);
			ps.setString(5, email);
			ps.setString(6,address);
			System.out.println(ename+"\t"+pass+"\t"+repass+"\t"+doj+"\t"+email+address);
			if (ps.executeUpdate()==1)
				return SUCCESS;			
		}
		catch (Exception e){}
		finally{
			try{
				if(con!=null)
					con.close();
			}
			catch (Exception e) {}
		}
		return ERROR;
	}

	public Connection getCon(){
		try{
			Class.forName("oracle.jdbc.driver.OracleDriver");
			con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","tiger");
			System.out.println("Connection:"+con);
		}
		catch(Exception e){}
		return con;
	}

}
